import { defineStore } from "pinia";
import { getCategoryListApi } from "@/service/category/category";
import type { CategoryItem } from "@/service/category/type";
import Swal from "sweetalert2";
export const useCategoryStore = defineStore("category", {
  state: () => ({
    categoryList: [] as CategoryItem[],
    total: 0,
    totalPages: 0,
  }),
  actions: {
    async getCategoryList(page?: number, pageSize?: number) {
      const res = await getCategoryListApi(page, pageSize);
      const { list, total, totalPages } = res.data;
      this.categoryList = list;
      this.total = total;
      this.totalPages = totalPages;
      return res.data;
    },
  },
});
